#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
	int data;
	struct Node *next;
} Node, *LinkList;

void MergeList(LinkList a, LinkList b);

int main() {
	int T = 0;
	int t = 0;
	scanf("%d", &T);
	for( t = 0; t < T; t++ ) { // Loop for T times 
		int lenA = 0, lenB = 0;
		int i = 0;
		scanf("%d", &lenA);
		scanf("%d", &lenB);
		// Input La in reverse sequence
		LinkList La;
		La = (LinkList)malloc(sizeof(Node));
		La->next = NULL;
		for ( i = 0; i < lenA; i++ ) {
			Node* p = NULL;
			p = (LinkList)malloc(sizeof(Node));	
			scanf("%d", &(p->data));
			p->next = La->next;
			La->next = p;		
		}
		// Input Lb in reverse sequence 
		LinkList Lb;
		Lb = (LinkList)malloc(sizeof(Node));
		Lb->next = NULL;
		for ( i = 0; i < lenB; i++ ) {
			Node* p = NULL;
			p = (LinkList)malloc(sizeof(Node));	
			scanf("%d", &(p->data));
			p->next = Lb->next;
			Lb->next = p;		
		}
		// Merge list La and Lb
		MergeList(La, Lb);
		// Generate list Lc
		LinkList Lc = La;
		// print the result
		Node* p = Lc->next;
		for ( i = 0; i < (lenA + lenB); i++ ) {
			printf("%d",p->data);
			p = p->next;
			if ( i == lenA + lenB - 1 ) {
				printf ("\n");
			}
			else printf(" ");
		}
	}
	return 0;
}

void MergeList(LinkList a, LinkList b) {
	LinkList NewP, pa, pb; 
	NewP = a;	 // Travel through the new list
	pa = a->next;// Travel through La
    pb = b->next;// Travel through Lb
    
    while (pa && pb)
    {
        if (pa->data <= pb->data) {
        	NewP->next = pa;
            pa = pa->next;
            NewP = NewP->next;
        }
        else {
            NewP->next = pb;
            pb = pb->next;
            NewP = NewP->next;
        }
    }
    NewP->next = pa ? pa : pb;// Insert the rest nodes
    free(b);    // free the header of Lb
    return; 
}
